#define Motor_Count 4 //定义直流电机数量
int motor_pin[4] = {5,6,9,10}; //定义直流电机引脚
const int enablePin = 11;

void Motor_pin_init() //初始化直流电机引脚
{
  for(int i=0;i<Motor_Count;i++)
  {
    pinMode(motor_pin[i],OUTPUT);
    digitalWrite(motor_pin[i], LOW);
  } 
}

void Motor_Go(int mode) //定义小车状态。mode表示小车模式，speeds表示小车速度
{
  switch(mode)
  {
    case slowForward: {
      // 两个电机都正转
      analogWrite(enablePin, 50); // 设置PWM值，范围0-255
      digitalWrite(motor_pin[0], HIGH);
      digitalWrite(motor_pin[1], LOW);
      digitalWrite(motor_pin[2], HIGH);
      digitalWrite(motor_pin[3], LOW);
      delay(1000);
    }break;
    case fastForward: {
      // 两个电机都正转
      analogWrite(enablePin, 200); // 设置PWM值，范围0-255
      digitalWrite(motor_pin[0], HIGH);
      digitalWrite(motor_pin[1], LOW);
      digitalWrite(motor_pin[2], HIGH);
      digitalWrite(motor_pin[3], LOW);
      delay(1000);
    }break;
    case Stop: {
      // 两个电机都停止
      for(int i = 0; i < Motor_Count; i++) {
        digitalWrite(motor_pin[i], LOW);
      }
      delay(1000);
    }break;
    default: break;   
  }
}
